def prime(skz):
    g = True
    for fs in range(2, int(skz ** 0.5)+1):
        if skz % fs == 0:
            g = False
            break
    return g

sas = int(input())
if sas < 1000 or sas > 9999:
    print(0)
else:
    bn = str(sas)
    v = 0
    for i in range(len(bn)):
        for t in range(i+1, len(bn)+1):
            nan = int(bn[i:t])
            if prime(nan):
                v = max(v, nan)
    print(v)
